import { Button, Layout, message } from "antd"
import { Content, Footer, Header } from "antd/es/layout/layout"
import Card from "../../components/LandingCard";
import { useNavigate } from "react-router-dom";
import { useEffect } from 'react';
import { GetToken } from "../../../api/User";
const headerStyle: React.CSSProperties = {
    textAlign: 'right',
    color: '#fff',
    backgroundColor: '#4096ff',
};

const contentStyle: React.CSSProperties = {
    textAlign: 'center',
    color: '#fff',
};


const layoutStyle: React.CSSProperties = {
    borderRadius: 8,
    overflow: 'hidden',
};

const Landing = () => {
    const navigate = useNavigate()
    const handleClick = () => {
        navigate('/login')
    }
    
    //自动登录
    useEffect(() => {
        const token = localStorage.getItem('token')
        // debugger
        console.log("本地获取"+token)
        GetToken().then(res => {
            console.log(res);
            // debugger
                if (res.data.data.token == token) {
                    message.success('自动登录')
                    navigate('/WorkSpace/GoodsList')
                }
                else {
                    message.error('身份已过期，请重新登录！')
                    navigate('/Login')
                }
            
        })
    },[])

    return (
        <>
            <Layout style={layoutStyle}>
                <Header style={headerStyle}>
                    <Button onClick={() => { handleClick() }}>登录/注册</Button>
                </Header>
                <Content style={contentStyle}>
                    <img style={{ width: '100%', height: 400 }} src="https://env-00jxgt5r6in3.normal.cloudstatic.cn/canvas.png?expire_at=1718629781&er_sign=313e7ab88586c9573a865ccf199dd0f9" alt="" />
                    <Card></Card>
                </Content>
                <Footer style={{ textAlign: 'center' }}>
                    Ant Design ©{new Date().getFullYear()} Created by Ant UED
                </Footer>
            </Layout>
        </>
    )
}

export default Landing